/*! \file clist.cpp	
	
	This contains the implementation of the ContainerList class
*/

#include "clist.h"


ContainerList::ContainerList( Component* parent ) :
	Container( parent )
{
}

void ContainerList::add( Component* c ) {
	Container::add( c );
	childChangedSize( c ); // update the height
}

void ContainerList::childChangedSize( Component* which ) {
	//~ int newH = 0;
	//~ list<Component*>::iterator i;
	//~ for ( i = children.begin(); i != children.end(); ++i ) {
		//~ newH += (*i)->getHeight();
	//~ }	
	//~ setHeight( newH );
}

void ContainerList::finalize() {
	int newH = 0;
	list<Component*>::iterator i;
	for ( i = children.begin(); i != children.end(); ++i ) {
		newH += (*i)->getHeight();
	}	
	setHeight( newH + 10);
}

void ContainerList::setSize( int newW, int newH ) {
	Component::setSize( newW, newH );
	list<Component*>::iterator i;
	
	for ( i = children.begin(); i != children.end(); ++i ) {
		cout << "Setting width to " << w - borderWidth * 2 << endl;
		(*i)->setWidth( w - borderWidth * 2 );
	}	
}
